/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_RENDERTARGET_H_
#define M_RENDERTARGET_H_

#include "refptr.h"
#include "timer.h"
#include "color.h"
#include "types.h"
#include "rendertargetvisitor.h"

#include <string>

namespace Engine
{
	/**
	*   This abstract class defines a common root to all targets of rendering operations. A render target could be a window, or offscreen surface like a texture or bump map etc.
	*/
	class RenderTarget
	{
	public:
		/**
		*   Constructor.
		*/
		RenderTarget();

		/**
		*   Destructor.
		*/
		virtual ~RenderTarget(){}

		/**
		*   Return objects name.
		*/
		virtual const std::string& GetName() const {return m_name;};

		/**
		*   Update targets content (render).
		*/
		virtual void Update(void);

		/**
		*   Return current FPS.
		*/
		virtual double GetFPS();

		/**
		*   Return number of rendered triangles in last frame.
		*/
		virtual unsigned int GetTriangleCount();

		/**
		*   Set camera for render target.
		*/
		virtual void SetCamera(CameraPtr camera);

		/**
		*   Sets the priority of this render target in relation to the others.Lower priorities will be rendered first.
		*/
		virtual void SetPriority( unsigned int priority ) { m_priority = priority; }

        /**
		*   Gets the priority of a render target.
		*/
		virtual unsigned int GetPriority() const { return m_priority; }

		/**
		*   Visitor implementation.
		*/
		virtual void Accept(RenderTargetVisitor& visitor) = 0;

		/**
		*   Return width.
		*/
		unsigned int GetWidth(){return m_width;}

		/**
		*   Return height.
		*/
		unsigned int GetHeight(){return m_height;}

		/**
		*   Return buffers width.
		*/
		virtual unsigned int GetBufferWidth() = 0;

		/**
		*   Return buffers height.
		*/
		virtual unsigned int GetBufferHeight() = 0;

		/**
		*   Set back ground color.
		*/
		void SetBackGroundColor(const Color& color);

		/**
		*   Return back ground color.
		*/
		const Color& GetBackGroundColor()const;

	protected:

		/**
		*   Update fps.
		*/
		void UpdateFPS();

	protected:

		unsigned int  m_priority;

		std::string   m_name;

		double        m_fps;

		unsigned long m_frameCount;

		unsigned long m_lastTime;
		unsigned long m_lastSecond;

		unsigned int  m_triangleCount;

		CameraPtr m_camera;

		Timer          m_timer;

		unsigned int m_width;
		unsigned int m_height;

		Color m_backGroundColor;
	};

}

#endif
